import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface MaterialProp {
  account_id: number;
  amount_unit: string;
  barcode: string;
  business_id: number;
  clean_time: number;
  cold_time: number;
  create_time: Date;
  delete_status: number;
  id: number;
  material_config: string;
  material_id: string;
  name: string;
  note: string;
  overdue_time: number;
  publish_status: number;
  type_id: number;
  type_name: string;
  update_time: string;
  use_barcode: boolean;
}

export const materialDelete = (data?: object) => {
  return http.request<ResultProps<MaterialProp[]>>("post", "/material/del", {
    data
  });
};

export const materialPublish = (data?: object) => {
  return http.request<ResultProps<MaterialProp[]>>(
    "post",
    "/material/publish",
    {
      data
    }
  );
};

export const getMaterialList = (params?: object) => {
  return http.request<ResultProps<MaterialProp[]>>(
    "get",
    "/material/getMaterialList",
    {
      params
    }
  );
};

export const getMaterialListForFormula = (params?: object) => {
  return http.request<ResultProps<{ [key: string]: any }[]>>(
    "get",
    "/formula/getDetail",
    {
      params
    }
  );
};

export const materialAdd = (data?: object) => {
  return http.request<ResultProps<MaterialProp[]>>("post", "/material/add", {
    data
  });
};
export const materialExportAdd = (data?: object) => {
  return http.request<ResultProps<MaterialProp[]>>(
    "post",
    "/material/add",
    {
      data
    },
    {
      beforeResponseCallback() {}
    }
  );
};

export const materialUpd = (data?: object) => {
  return http.request<ResultProps<MaterialProp[]>>("post", "/material/upd", {
    data
  });
};

export interface MaterialTypeProp {
  id: number;
  account_id: number;
  business_id: number;
  name: string;
  note: null | string;
  delete_status: number;
  update_time: Date;
  create_time: Date;
}

export const getMaterialTypeList = (data?: object) => {
  return http.request<ResultProps<MaterialTypeProp[]>>(
    "get",
    "/materialType/getMaterialTypeList",
    {
      params: data
    }
  );
};

export const materialTypeAdd = (data?: object) => {
  return http.request<ResultProps<MaterialProp>>("post", "/materialType/add", {
    data
  });
};

export const materialTypeUpd = (data?: object) => {
  return http.request<ResultProps<null>>("post", "/materialType/upd", {
    data
  });
};

export const materialTypeDel = (data?: object) => {
  return http.request<ResultProps<null>>("post", "/materialType/del", {
    data
  });
};
